### Replication File for 
### "Does Ideology Influence Hiring in China? Evidence from Two Randomized Experiments"
### Jennifer Pan and Tongtong Zhang

### This file: codes that replicate all tables and statistics in online appendices

######################################################################################
## Section A.1 Resume Design Process
######################################################################################
## Load data
rm(list=ls())
# Please set the working directory to the folder where the ReadMe.txt is located.
# setwd("")
d<-read.csv("Data/Pretest1_SelectTreatment.csv",stringsAsFactors = FALSE,sep=",")

## Load packages
#install.packages("sandwich")
#install.packages("lmtest")
#install.packages("stargazer")
suppressMessages(library(lmtest))
suppressMessages(library(stargazer))

## Function to compute var-cov matrix using clustered robust standard errors
vcovCluster <- function(
  model,
  cluster
)
{
  require(sandwich)
  require(lmtest)
  if(nrow(model.matrix(model))!=length(cluster)){
    stop("check your data: cluster variable has different N than model")
  }
  M <- length(unique(cluster))
  N <- length(cluster)           
  K <- model$rank   
  if(M<50){
    warning("Fewer than 50 clusters, variances may be unreliable (could try block bootstrap instead).")
  }
  dfc <- (M/(M - 1)) * ((N - 1)/(N - K))
  uj  <- apply(estfun(model), 2, function(x) tapply(x, cluster, sum));
  rcse.cov <- dfc * sandwich(model, meat = crossprod(uj)/N)
  return(rcse.cov)
}


###############################
####### Table A2 #############
###############################
## Row 1: Effects of Master's major on different outcomes
# Outcome: rating of conformity
m_major<-lm(allegiance~marxist_major,data=d)
marx_major_allegiance<-coeftest(m_major,vcov=vcovCluster(m_major,cluster=d$respondent))
# Outcome: rating of academic merit
m_major<-lm(merit~marxist_major,data=d)
marx_major_merit<-coeftest(m_major,vcov=vcovCluster(m_major,cluster=d$respondent))
# Outcome: rating of political connections
m_major<-lm(connections~marxist_major,data=d)
marx_major_connections<-coeftest(m_major,vcov=vcovCluster(m_major,cluster=d$respondent))
# Store results
Row1<-stargazer(marx_major_allegiance,marx_major_merit,marx_major_connections, type="text", digits=2,
                omit=c("Constant","Constant","Constant"), column.labels = c("conformity","merit","connection"),
                title="Table A2 Row 1, columns 1-3 (see column 4 in the end)", covariate.labels=c("Master's major"))

## Row 2: Effects of Highlighted courses on different outcomes
# Outcome: rating of conformity
m_course<-lm(allegiance~marxist_course,data=d)
marx_course_allegiance<-coeftest(m_course,vcov=vcovCluster(m_course,cluster=d$respondent))
marx_course_allegiance
# Outcome: rating of academic merit
m_course<-lm(merit~marxist_course,data=d)
marx_course_merit<-coeftest(m_course,vcov=vcovCluster(m_course,cluster=d$respondent))
marx_course_merit
# Outcome: rating of political connections
m_course<-lm(connections~marxist_course,data=d)
marx_course_connections<-coeftest(m_course,vcov=vcovCluster(m_course,cluster=d$respondent))
marx_course_connections
# Store results
Row2<-stargazer(marx_course_allegiance,marx_course_merit,marx_course_connections, type="text", digits=2,
                omit=c("Constant","Constant","Constant"), column.labels = c("conformity","merit","connection"),
                title="Table A2 Row 2, columns 1-3", covariate.labels=c("Highlighted courses"))

## Row 3: Effects of extracurricular study group on different outcomes
# Outcome: rating of conformity
m_extra<-lm(allegiance~marxist_extra,data=d)
marx_extra_allegiance<-coeftest(m_extra,vcov=vcovCluster(m_extra,cluster=d$respondent))
# Outcome: rating of academic merit
m_extra<-lm(merit~marxist_extra,data=d)
marx_extra_merit<-coeftest(m_extra,vcov=vcovCluster(m_extra,cluster=d$respondent))
# Outcome: rating of political connections
m_extra<-lm(connections~marxist_extra,data=d)
marx_extra_connections<-coeftest(m_extra,vcov=vcovCluster(m_extra,cluster=d$respondent))
# Store results
Row3<-stargazer(marx_extra_allegiance,marx_extra_merit,marx_extra_connections, type="text", digits=2,
                omit=c("Constant","Constant","Constant"), column.labels = c("conformity","merit","connection"),
                title="Table A2 Row 3, columns 1-3", covariate.labels=c("Extracurricular study group"))

### Columnn 4: Objective Function D
# Candidate proxy: Master's major
marx_major_allegiance<-round(marx_major_allegiance[2,c(1,2,4)], digits=1);marx_major_connections<-round(marx_major_connections[2,c(1,2,4)],digits=1);marx_major_merit<-round(marx_major_merit[2,c(1,2,4)], digits=1)
d1<-marx_major_allegiance[1] - (abs(marx_major_merit[1]) + abs(marx_major_connections[1]))
# Candidate proxy: Highlighted courses
marx_course_allegiance<-round(marx_course_allegiance[2,c(1,2,4)], digits=1); marx_course_merit<-round(marx_course_merit[2,c(1,2,4)],digits=2);marx_course_connections<-round(marx_course_connections[2,c(1,2,4)],digits=2)
d2<-marx_course_allegiance[1] - (abs(marx_course_merit[1]) + abs(marx_course_connections[1]))
# Candidate proxy: Extracurricular study group
marx_extra_allegiance<-round(marx_extra_allegiance[2,c(1,2,4)], digits=2);marx_extra_merit<-round(marx_extra_merit[2,c(1,2,4)],digits=2);marx_extra_connections<-round(marx_extra_connections[2,c(1,2,4)],digits=2)
d3<-marx_extra_allegiance[1] - (abs(marx_extra_merit[1]) + abs(marx_extra_connections[1]))
# Store results
D<-matrix(NA,ncol=1,nrow=6)
D[,1]<-c("","Table A2 Column 4","D",d1,d2,d3)

## Save the table
results<-c(Row1,Row2,Row3,D)
write.table(results, file="Log/TableA2.txt", row.names = FALSE)

######################################################################################
## Section A.2 Audit Experiment Implementation
######################################################################################
## Load data
rm(list=ls())  
d<-read.csv("Data/ExternalValidity.csv",header=TRUE, stringsAsFactors = FALSE,sep=",") 

###############################
####### Table A3 #############
###############################
## Column 1: regional and sectoral distribution of all jobs
dist_all<-c(mean(d$gov,na.rm=TRUE),mean(d$soe,na.rm=TRUE), mean(d$private,na.rm=TRUE), 
            mean(d$foreign,na.rm=TRUE),mean(d$nonprofit,na.rm=TRUE),
            mean(d$comm_edu,na.rm=TRUE), mean(d$energy,na.rm=TRUE),
            mean(d$real_estate,na.rm=TRUE),mean(d$tech,na.rm=TRUE), 
            mean(d$finance,na.rm=TRUE),mean(d$auto_manufact,na.rm=TRUE), 
            mean(d$health,na.rm=TRUE), mean(d$consumer,na.rm=TRUE),
            mean(d$agriculture,na.rm=TRUE), mean(d$other_service,na.rm=TRUE),
            mean(d$east,na.rm=TRUE), mean(d$middle,na.rm=TRUE), 
            mean(d$west,na.rm=TRUE),mean(d$cross,na.rm=TRUE),
            mean(d$tech_job,na.rm=TRUE),mean(d$professional,na.rm=TRUE), 
            mean(d$teacher,na.rm=TRUE), mean(d$secretariat,na.rm=TRUE),
            mean(d$service,na.rm=TRUE), mean(d$worker,na.rm=TRUE))
dist_all<-round(dist_all*100,digits=1)

## Column 2: regional and sectoral distribution of applied jobs
applied<-subset(d,applied==1) #take out applied employer-location 
dist_applied<-c(mean(applied$gov,na.rm=TRUE),mean(applied$soe,na.rm=TRUE), 
                mean(applied$private,na.rm=TRUE), mean(applied$foreign,na.rm=TRUE),
                mean(applied$nonprofit,na.rm=TRUE), mean(applied$comm_edu,na.rm=TRUE), 
                mean(applied$energy,na.rm=TRUE), mean(applied$real_estate,na.rm=TRUE),
                mean(applied$tech,na.rm=TRUE), mean(applied$finance,na.rm=TRUE),
                mean(applied$auto_manufact,na.rm=TRUE), mean(applied$health,na.rm=TRUE), 
                mean(applied$consumer,na.rm=TRUE), mean(applied$agriculture,na.rm=TRUE), 
                mean(applied$other_service,na.rm=TRUE), mean(applied$east,na.rm=TRUE), 
                mean(applied$middle,na.rm=TRUE), mean(applied$west,na.rm=TRUE),
                mean(applied$cross,na.rm=TRUE), mean(applied$tech_job,na.rm=TRUE),
                mean(applied$professional,na.rm=TRUE), mean(applied$teacher,na.rm=TRUE), 
                mean(applied$secretariat,na.rm=TRUE),mean(applied$service,na.rm=TRUE), 
                mean(applied$worker,na.rm=TRUE))
dist_applied<-round(dist_applied*100,digits=1)

## Column 3: p-values between all and applied jobs
covar<-c("gov","soe","private","foreign",
         "nonprofit","comm_edu","energy","real_estate","tech","finance",
         "auto_manufact","health","consumer","agriculture","other_service",
         "east","middle","west","cross",
         "tech_job","professional","teacher","secretariat","service","worker")
p<-rep(NA,length(covar)) #store p-value
for (i in 1:length(covar)){
  p[i]<- t.test(d[,covar[i]],applied[,covar[i]])$p.value
}
p<-formatC(p, format="g", digits=2)

## Save the table
covars<-c("Public institution","State-owned enterprise","Private","Foreign/JV",
         "Non-profit","Media and education","Energy and resource","Real estate",
         "Technology","Finance","Automotive and manufacturing",
         "Health","Consumer","Agriculture","Other (service)",
         "East","Middle","West","Cross-regional",
         "Technical job","Professional","Teacher",
         "Secretarial","Blue collar service","Blue collar worker")
results<-cbind.data.frame(covars,dist_all,dist_applied,p)
colnames(results)<-c("Characteristics","All jobs","Applied jobs","p-value")
results<-stargazer(results,title="Table A3",
                   type="text",summary=FALSE,digits=2)
write.table(results, file="Log/TableA3.txt", row.names = FALSE)

######################################################################################
## Section A.3 Audit Experiment Overall Effect Details
######################################################################################
rm(list=ls())  
d<-read.csv("Data/ResumeAudit.csv",header=TRUE, stringsAsFactors = FALSE,sep=",") 
colnames(d)
#install.packages("plm")
#install.packages("lmtest")
#install.packages("mfx")
#install.packages("multiwayvcov")
suppressMessages(library(plm))
suppressMessages(library(lmtest))
suppressMessages(library(mfx))
suppressMessages(library(multiwayvcov))

###############################
####### Table A4 #############
###############################
## Colmun 1: Observations
obs<-rep(19221,4)
## Colmun 2: Means of covariates for the apolitical control group
Control<-c(mean(d$merit[d$apolitical==1]),mean(d$male[d$apolitical==1]),mean(d$ccp[d$apolitical==1]),
           mean(d$high_tier[d$apolitical==1]))
## Colmun 3: Means of covariates for the conformity group
Conformity<-c(mean(d$merit[d$conformity==1]),mean(d$male[d$conformity==1]),mean(d$ccp[d$conformity==1]),
              mean(d$high_tier[d$conformity==1]))
## Colmun 4: Means of covariates for the Non-conformity group
NonConformity<-c(mean(d$merit[d$non_conformity==1]),mean(d$male[d$non_conformity==1]),mean(d$ccp[d$non_conformity==1]),
                 mean(d$high_tier[d$non_conformity==1]))
## Colmun 5: P-value from the F test with both treatment dummies
p_merit<-pf(summary(lm(merit~conformity+non_conformity,data=d))$fstatistic[1],summary(lm(merit~conformity+non_conformity,data=d))$fstatistic[2],
            summary(lm(merit~conformity+non_conformity,data=d))$fstatistic[3], lower.tail=FALSE)
p_male<-pf(summary(lm(male~conformity+non_conformity,data=d))$fstatistic[1],summary(lm(male~conformity+non_conformity,data=d))$fstatistic[2],
           summary(lm(male~conformity+non_conformity,data=d))$fstatistic[3], lower.tail=FALSE)
p_ccp<-pf(summary(lm(ccp~conformity+non_conformity,data=d))$fstatistic[1],summary(lm(ccp~conformity+non_conformity,data=d))$fstatistic[2],
            summary(lm(ccp~conformity+non_conformity,data=d))$fstatistic[3], lower.tail=FALSE)
p_high_tier<-pf(summary(lm(high_tier~conformity+non_conformity,data=d))$fstatistic[1],summary(lm(high_tier~conformity+non_conformity,data=d))$fstatistic[2],
                summary(lm(high_tier~conformity+non_conformity,data=d))$fstatistic[3], lower.tail=FALSE)
pvalue<-c(p_merit,p_male,p_ccp,p_high_tier)
balance<-cbind.data.frame(obs,Control,Conformity,NonConformity,pvalue)
rownames(balance)<-c("High GPA ranking","Male","CCP member","Higher-tier university")
colnames(balance)[c(1,2,5)]<-c("Obs","Apolitical","p-value")

## Save the table
results<-round(balance,digits=3)
results<-stargazer(results,title="Table A4",
                   type="text",summary=FALSE,digits=3)
write.table(results, file="Log/TableA4.txt", row.names = FALSE)


###############################
####### Table A5 #############
###############################
callback_rate<-rep(NA,16) #column 1: callback rate
observations<-rep(NA,16) #column 2: number of resumes

## Overall
callback_rate[1]<-mean(d$callback)
observations[1]<-dim(d)[1]
## By Ideological Allegiance
# Apolitical
callback_rate[2]<-mean(subset(d, allegiance=="comic")$callback)
observations[2]<-length(subset(d, allegiance=="comic")$callback)
# Conformity
callback_rate[3]<-mean(subset(d, allegiance=="socialism")$callback)
observations[3]<-length(subset(d, allegiance=="socialism")$callback)
# Non-conformity
callback_rate[4]<-mean(subset(d, allegiance=="western")$callback)
observations[4]<-length(subset(d, allegiance=="western")$callback)
## By academic merit
# High merit
callback_rate[5]<-mean(subset(d, merit==1)$callback)
observations[5]<-length(subset(d, merit==1)$callback)
# Average merit
callback_rate[6]<-mean(subset(d, merit==0)$callback)
observations[6]<-length(subset(d, merit==0)$callback)
## By prestige of university
# High tier
callback_rate[7]<-mean(subset(d, high_tier==1)$callback)
observations[7]<-length(subset(d, high_tier==1)$callback)
# Low tier
callback_rate[8]<-mean(subset(d, high_tier==0)$callback)
observations[8]<-length(subset(d, high_tier==0)$callback)
## By gender
# Male
callback_rate[9]<-mean(subset(d, male==1)$callback)
observations[9]<-length(subset(d, male==1)$callback)
# Female
callback_rate[10]<-mean(subset(d, male==0)$callback)
observations[10]<-length(subset(d, male==0)$callback)
## By CCP membership
# CCP member
callback_rate[11]<-mean(subset(d, ccp==1)$callback)
observations[11]<-length(subset(d, ccp==1)$callback)
# Non-CCP member
callback_rate[12]<-mean(subset(d, ccp ==0)$callback)
observations[12]<-length(subset(d, ccp ==0)$callback)
## By sector
# Public sector
callback_rate[13]<-mean(subset(d, public==1)$callback)
observations[13]<-length(subset(d, public==1)$callback)
# State-owned enterprise (SOE)
callback_rate[14]<-mean(subset(d, soe==1)$callback)
observations[14]<-length(subset(d, soe==1)$callback)
# Private
callback_rate[15]<-mean(subset(d, private==1)$callback)
observations[15]<-length(subset(d, private==1)$callback)
# Foreign
callback_rate[16]<-mean(subset(d, foreign==1)$callback)
observations[16]<-length(subset(d, foreign==1)$callback)

## Save the table
covars<-c("Overall","Apolitical","Conformity","Non-conformity",
          "High merit","Average merit","Higher-tier university",
          "Lower-tier university","Male","Female","CCP member",
          "Non-CCP member","Public institution","State-owned enterprise",
          "Private firm","Foreign/Joint venture")
tableA5<-cbind.data.frame(covars,round(callback_rate,digits=3),observations)
colnames(tableA5)<-c("Characteristics","Callback rate","Number of resumes")
results<-stargazer(tableA5,title="Table A5",
                   type="text",summary=FALSE,digits=3)
write.table(results, file="Log/TableA5.txt", row.names = FALSE)


###############################
####### Table A6 #############
###############################
# Column 1: OLS, no control
ols.nc1 <- lm(callback ~ conformity+non_conformity, data = d)
vcovCL.nc1<-cluster.vcov(ols.nc1, d$job_identifier) #robust s.e. clustered on the job level
model1<-coeftest(ols.nc1, vcov = vcovCL.nc1)

# Column 2: OLS, with vacancy fixed-effects
d$resume_index <- as.factor(d$allegiance)
dd <- pdata.frame(d, index = c("job_identifier", "resume_index")) #under each unique job, 3 resumes submitted
ols.fe <- plm(callback ~ conformity + non_conformity, data=dd, model="within") 
model2<-coeftest(ols.fe, vcov=function(x) vcovHC(x, cluster="group", type="HC1")) 

# Column 3: OLS, with controls:
covars <- c("male","high_tier","ccp", "cs", "ee", "econ", "med", "soe", "private", "foreign",
            "javascript", "linux", "php", "python","sql", 
            "running400", "running800", "highjump", "longjump", "shotput", "swim",
            "badminton", "biking", "rollerskate", "music","UJobSameProvince","university_east",
            "university_west")
X<-as.matrix(d[,covars])
X_demean <- X - predict(lm(X~rep(1,dim(d)[1]))) #demean each control
ols.c1 <- lm(callback ~ conformity + non_conformity + X_demean + (conformity + non_conformity)*X_demean, data = d)
vcovCL.c1<-cluster.vcov(ols.c1, d$job_identifier) 
model3<-coeftest(ols.c1, vcov = vcovCL.c1)

## Save the table
results<-stargazer(model1, model2, model3, title=c("Table A6"), 
                   align=TRUE, digits=3, type="text",
                   omit=c("X_", "Constant"),
                   no.space = T,
                   add.lines = list(c("Observation","19221","19221","19221"))) 
                   
write.table(results, file="Log/TableA6.txt", row.names = FALSE)


######################################################################################
## Section A.4 Audit Experiment Heterogeneous Effect Detail
######################################################################################

###############################
####### Table A7 #############
###############################
# Column 1: Public institutions vs. all other ownership sectors (OLS)
ols.pool.nc1 <- lm(callback ~ non_conformity*public, data = d)
vcovCL.pool.nc1<-cluster.vcov(ols.pool.nc1, d$job_identifier)
model1<-coeftest(ols.pool.nc1, vcov = vcovCL.pool.nc1)
# Column 2: SOE vs. all other ownership sectors (OLS)
ols.pool.nc1 <- lm(callback ~ non_conformity*soe, data = d) 
vcovCL.pool.nc1<-cluster.vcov(ols.pool.nc1, d$job_identifier)
model2<-coeftest(ols.pool.nc1, vcov = vcovCL.pool.nc1)
# Column 3: Private vs. all other ownership sectors (OLS)
ols.pool.nc1 <- lm(callback ~ non_conformity*private, data = d) 
vcovCL.pool.nc1<-cluster.vcov(ols.pool.nc1, d$job_identifier) 
model3<-coeftest(ols.pool.nc1, vcov = vcovCL.pool.nc1)
# Column 4: Foreign vs. all other ownership sectors (OLS)
ols.pool.nc1 <- lm(callback ~ non_conformity*foreign, data = d) 
vcovCL.pool.nc1<-cluster.vcov(ols.pool.nc1, d$job_identifier) 
model4<-coeftest(ols.pool.nc1, vcov = vcovCL.pool.nc1)
# Column 5: Public institutions vs. all other ownership sectors (Logit)
model5<-logitmfx(callback ~ non_conformity*public, data = d)
coef5<-model5$mfxest[,1]
se5<-model5$mfxest[,2]
# Column 6: SOE vs. all other ownership sectors (Logit)
model6<-logitmfx(callback ~ non_conformity*soe, data = d)
coef6<-model6$mfxest[,1]
se6<-model6$mfxest[,2]
# Column 7: Private vs. all other ownership sectors (Logit)
model7<-logitmfx(callback ~ non_conformity*private, data = d)
coef7<-model7$mfxest[,1]
se7<-model7$mfxest[,2]
# Column 8: Foreign vs. all other ownership sectors (Logit)
model8<-logitmfx(callback ~ non_conformity*foreign, data = d)
coef8<-model8$mfxest[,1]
se8<-model8$mfxest[,2]

## Save the table
results<-stargazer(model1, model2, model3, model4, model5$fit,
                   model6$fit, model7$fit, model8$fit,
                   coef=list(model1[,1],model2[,1],model3[,1],model4[,1],coef5,coef6,coef7,coef8),
                   se=list(model1[,2],model2[,2],model3[,2],model4[,2],se5,se6,se7,se8),
                   title=c("Table A7"), order=c(3,5,7,9,1,2,4,6,8),
                   align=TRUE, digits=3, type="text",
                   omit=c("Constant"), omit.stat=c("all"),
                   no.space = T, dep.var.labels.include = F,
                   add.lines = list(c("Apolitical and conformity callback in others", 
                   rep(c(round(model1[1,1],digits=3),round(model2[1,1],digits=3),
                        round(model3[1,1],digits=3),round(model4[1,1],digits=3)),2)),
                   c("Observation",rep("19221",8)))) 
write.table(results, file="Log/TableA7.txt", row.names = FALSE)


###############################
####### Table A8 #############
###############################
# Column 1: Specialized permits vs. no specialized permits (OLS)
model1 <- lm(callback ~ non_conformity + non_conformity*Special_Permits, data = d) 
vcovCL.model1<-cluster.vcov(model1, d$job_identifier) 
model1<-coeftest(model1, vcov = vcovCL.model1)
coef1<-model1[,1]
se1<-model1[,2]
# Column 2: Specialized permits vs. no specialized permits (Logit)
model2<-logitmfx(callback ~ non_conformity*Special_Permits, data=d, atmean=F)
coef2<-model2$mfxest[,1]
se2<-model2$mfxest[,2]

## Save the table
results<-stargazer(model1, model2$fit,
                   coef=list(coef1,coef2),
                   se=list(se1,se2),
                   title=c("Table A8"), order=c(3,1,2),
                   align=TRUE, digits=3, type="text",
                   omit=c("Constant"), omit.stat=c("all"),
                   no.space = T, dep.var.labels.include = F,
                   add.lines = list(c("Apolitical and conformity callback in others", 
                                   round(model1[1,1],digits=3),round(model1[1,1],digits=3)),
                                    c("Observation",rep("19221",2)))) 
write.table(results, file="Log/TableA8.txt", row.names = FALSE)



###############################
####### Table A9 #############
###############################

# Per IRB requirement, we cannot disclose the names of firms involved in this study.
# So, below we provided and commented out the R codes we used 
# to conduct the STM analysis and obtained the keywords for each topic

## Step 1: Pre-processing firm names
#rm(list=ls())
#pkgs <- c("stm", "tm")
#sapply(pkgs, require, character.only=TRUE)
#vacancy<-read.csv("vacancy_raw.csv",header=TRUE, stringsAsFactors = FALSE,sep=",")
#colnames(vacancy)
#vacancy$Employers_seg<-gsub("[A-Za-z]", "", vacancy$Employers_seg)
#vacancy$Employers_seg<-gsub("[0-9]", "", vacancy$Employers_seg)
#c_stopwords<-c("\n", "delimiter","是","的","吗","不","请","于","了","啊","在","微博",
#               "微","博","我","我们","你","你们","他","他们","她","她们","呢","您",
#               "一","个","却","几","能否","什么","有限","公司","集团","分公司","责任","股份","企业") 
#temp_employers <- textProcessor(documents=vacancy$Employers_seg, 
#                                metadata=vacancy,
#                                removestopwords=TRUE, removenumbers=TRUE,
#                                removepunctuation=TRUE, ucp=TRUE, 
#                                customstopwords=c_stopwords,
#                                custompunctuation=c("：", "，", "。","#","@","【", "】", 
#                                                   "《","》","、","；","`","-","——"),  
#                               wordLengths=c(1,6))
#length(temp_employers$vocab) #6400 terms
#length(temp_employers$documents) #6296 firm names
#plotRemoved(temp_employers$documents, lower.thresh = seq(1, 20, by = 1))
## Prep documents (keep terms appearing in [1, 99%] of all firm names)
#bout_employers <- prepDocuments(temp_employers$documents, temp_employers$vocab, temp_employers$meta, 
#                               lower.thresh=1, upper.thres=6234)
#docs_employers <- out_employers$documents
#meta_employers <- out_employers$meta
#vocab_employers <- out_employers$vocab
#length(docs_employers) #6157 unique firm names after pre-processing
#length(vocab_employers) #1871 unique terms after pre-processing
#rm(out_employers,temp_employers)

## Step 2: Choose K topics based on coherence and exclusivity
#set.seed(210324)
#storage <- searchK(GScont.docs_employers, GScont.vocab_employers, 
#                   K = c(seq(10,18, by=1)),
#                   N=floor(0.1 * length(GScont.docs_employers)),
#                   data = GScont.meta_employers)
#K_models <- as.data.frame(storage$results)
#plot.searchK(storage)
## 12 topics chosen: perform relatively well on residuals, semantic coherence, exclusivity, and held-out

## Step 3: Estimate STM model with the selected K
#K <- 12
#set.seed(210324)
#cont_employers <- stm(docs_employers, vocab_employers, K=K, 
#                      data=meta_employers)
#checkResiduals(cont_employers, docs_employers, tol=0.01)
#checkBeta(cont_employers, tolerance = 0.01)

## Step 4: Get the keywords associated with each topic
#sink("Employers_words.txt")
#labelTopics(cont_employers, n=5) #showing the top 5 words associated with each topic
#sink()


###############################
####### Table A10 #############
###############################
# Column 1: CCP prioirty + innovative vs. all other firms (OLS)
model <- lm(callback ~ non_conformity*priority_innovation, data = d) 
vcovCL.model<-cluster.vcov(model, d$job_identifier)
model1<-coeftest(model, vcov = vcovCL.model)
# Column 2: Not CCP prioirty + innovative vs. all other firms (OLS)
model <- lm(callback ~ non_conformity*Nonpriority_innovation, data = d) 
vcovCL.model<-cluster.vcov(model, d$job_identifier)
model2<-coeftest(model, vcov = vcovCL.model)
# Column 3: CCP prioirty + not innovative vs. all other firms (OLS)
model <- lm(callback ~ non_conformity*priority_Notinnovation, data = d)
vcovCL.model<-cluster.vcov(model, d$job_identifier) 
model3<-coeftest(model, vcov = vcovCL.model)
# Column 4: Not CCP prioirty + not innovative vs. all other firms (OLS)
model <- lm(callback ~ non_conformity*Nonpriority_Noninnovation, data = d) 
vcovCL.model<-cluster.vcov(model, d$job_identifier)
model4<-coeftest(model, vcov = vcovCL.model)
# Column 5: CCP prioirty + innovative vs. all other firms (Logit)
model5<-logitmfx(callback ~ non_conformity*priority_innovation, data = d, atmean=F)
coef5<-model5$mfxest[,1]
se5<-model5$mfxest[,2]
# Column 6: Not CCP prioirty + innovative vs. all other firms (Logit)
model6<-logitmfx(callback ~ non_conformity*Nonpriority_innovation, data = d, atmean=F)
coef6<-model6$mfxest[,1]
se6<-model6$mfxest[,2]
# Column 7: CCP prioirty + not innovative vs. all other firms (Logit)
model7<-logitmfx(callback ~ non_conformity*priority_Notinnovation, data = d, atmean=F)
coef7<-model7$mfxest[,1]
se7<-model7$mfxest[,2]
# Column 8: Not CCP prioirty + not innovative vs. all other firms (Logit)
model8<-logitmfx(callback ~ non_conformity*Nonpriority_Noninnovation, data = d, atmean=F)
coef8<-model8$mfxest[,1]
se8<-model8$mfxest[,2]

## Save the table
results<-stargazer(model1, model2, model3, model4, model5$fit,
                   model6$fit, model7$fit, model8$fit,
                   coef=list(model1[,1],model2[,1],model3[,1],model4[,1],coef5,coef6,coef7,coef8),
                   se=list(model1[,2],model2[,2],model3[,2],model4[,2],se5,se6,se7,se8),
                   title=c("Table A10"), order=c(3,5,7,9,1,2,4,6,8),
                   align=TRUE, digits=3, type="text",
                   omit=c("Constant"), omit.stat=c("all"),
                   no.space = T, dep.var.labels.include = F,
                   add.lines = list(c("Apolitical and conformity callback in others", 
                                      rep(c(round(model1[1,1],digits=3),round(model2[1,1],digits=3),
                                            round(model3[1,1],digits=3),round(model4[1,1],digits=3)),2)),
                                    c("Observation",rep("19221",8)))) 
write.table(results, file="Log/TableA10.txt", row.names = FALSE)

###############################
####### Table A11 #############
###############################
## CCP prioirty + innovative
# OLS
dd<-d[(d$Innovation==1 & d$State_Priority==1),]
model1 <- lm(callback ~ non_conformity, data = dd)
vcovCL.model1<-cluster.vcov(model1, dd$job_identifier) 
model1<-coeftest(model1, vcov = vcovCL.model1)
# Logit
dd<-d[(d$Innovation==1 & d$State_Priority==1),]
model2<-logitmfx(callback ~ non_conformity , data = dd, atmean=F)
coef2<-c(1,model2$mfxest[,1])
se2<-c(1,model2$mfxest[,2])
panel1<-stargazer(model1, model2$fit,
                   coef=list(model1[,1],coef2),
                   se=list(model1[,2],se2),
                   title=c("Table A11 - Panel 1: CCP priority, innovative"), 
                   digits=3, type="text", omit=c("Constant"),
                  omit.stat=c("all"), 
                   no.space = T, dep.var.labels.include = F,
                   add.lines = list(c("Apolitical and conformity callback", 
                                      rep(round(model1[1,1],digits=3),2)),
                                    c("Observation",rep(dim(dd)[1],2)))) 


## Not CCP prioirty + innovative
# OLS
dd<-d[(d$Innovation==1 & d$State_Priority==0),]
model1 <- lm(callback ~ non_conformity, data = dd)
vcovCL.model1<-cluster.vcov(model1, dd$job_identifier)
model1<-coeftest(model1, vcov = vcovCL.model1)
# Logit
dd<-d[(d$Innovation==1 & d$State_Priority==0),]
model2<-logitmfx(callback ~ non_conformity, data = dd, atmean=F)
coef2<-c(1,model2$mfxest[,1])
se2<-c(1,model2$mfxest[,2])
panel2<-stargazer(model1, model2$fit,
                  coef=list(model1[,1],coef2),
                  se=list(model1[,2],se2),
                  title=c("Panel 2: Not CCP priority, innovative"), 
                  digits=3, type="text", omit=c("Constant"),
                  omit.stat=c("all"), 
                  no.space = T, dep.var.labels.include = F,
                  add.lines = list(c("Apolitical and conformity callback", 
                                     rep(round(model1[1,1],digits=3),2)),
                                   c("Observation",rep(dim(dd)[1],2)))) 

## CCP prioirty + not innovative
# OLS
dd<-d[(d$Innovation==0 & d$State_Priority==1),]
model1 <- lm(callback ~ non_conformity, data = dd)
vcovCL.model1<-cluster.vcov(model1, dd$job_identifier) 
model1<-coeftest(model1, vcov = vcovCL.model1)
# Logit
dd<-d[(d$Innovation==0 & d$State_Priority==1),]
model2<-logitmfx(callback ~ non_conformity, data = dd, atmean=F)
coef2<-c(1,model2$mfxest[,1])
se2<-c(1,model2$mfxest[,2])
panel3<-stargazer(model1, model2$fit,
                  coef=list(model1[,1],coef2),
                  se=list(model1[,2],se2),
                  title=c("Panel 3: CCP priority, not innovative"), 
                  digits=3, type="text", omit=c("Constant"),
                  omit.stat=c("all"), 
                  no.space = T, dep.var.labels.include = F,
                  add.lines = list(c("Apolitical and conformity callback", 
                                     rep(round(model1[1,1],digits=3),2)),
                                   c("Observation",rep(dim(dd)[1],2)))) 

## Not CCP prioirty + not innovative
# OLS
dd<-d[(d$Innovation==0 & d$State_Priority==0),]
model1 <- lm(callback ~ non_conformity, data = dd)
vcovCL.model1<-cluster.vcov(model1, dd$job_identifier)
model1<-coeftest(model1, vcov = vcovCL.model1)
# Logit
dd<-d[(d$Innovation==0 & d$State_Priority==0),]
model2<-logitmfx(callback ~ non_conformity, data = dd, atmean=F)
coef2<-c(1,model2$mfxest[,1])
se2<-c(1,model2$mfxest[,2])
panel4<-stargazer(model1, model2$fit,
                  coef=list(model1[,1],coef2),
                  se=list(model1[,2],se2),
                  title=c("Panel 4: Not CCP priority, not innovative"), 
                  digits=3, type="text", omit=c("Constant"),
                  omit.stat=c("all"), 
                  no.space = T, dep.var.labels.include = F,
                  add.lines = list(c("Apolitical and conformity callback", 
                                     rep(round(model1[1,1],digits=3),2)),
                                   c("Observation",rep(dim(dd)[1],2)))) 

## Save the table
results<-c(panel1,panel2,panel3,panel4)
write.table(results, file="Log/TableA11.txt", row.names = FALSE)


###############################
####### Table A12 #############
###############################
# Column 1: Effect of higher tier university
model1 <- glm(callback ~ high_tier, family=binomial(), data = d)
# Column 2: Effect of being a male applicant
model2 <- glm(callback ~ male, family=binomial(),data = d)
# Column 3: Effect of geographic proximity
model3 <- glm(callback ~ UJobSameProvince, family=binomial(),data = d)

# Save the table
results<-stargazer(model1, model2, model3,
                  covariate.labels = c("Higher-tier","Male","Geographic proximity"),
                  title=c("Table A12"), 
                  digits=3, type="text", omit=c("Constant"),
                  omit.stat=c("all"), 
                  no.space = T, dep.var.labels.include = F,
                  add.lines = list(c("Observation",rep(dim(d)[1],3)))) 
write.table(results, file="Log/TableA12.txt", row.names = FALSE)


###############################
####### Table A13 #############
###############################
## Split the data into four sectors
d$resume_index <- as.factor(d$allegiance)
d_public <- subset(d, public ==1)
d_private <- subset(d, private ==1)
d_foreign <- subset(d, foreign ==1)
d_soe <- subset(d, soe ==1)

## Public sector
m1_public<-subset(d_public, merit == 1)
m0_public<-subset(d_public, merit == 0)
#Column 1: No control
ols.nc1.m1.public <- lm(callback ~ conformity+non_conformity, data = m1_public) 
vcovCL.nc1.m1.public<-cluster.vcov(ols.nc1.m1.public, m1_public$job_identifier)
model1<-coeftest(ols.nc1.m1.public, vcov = vcovCL.nc1.m1.public)
#Column 2: vacancy-fixed effects
dd_m1_public <- pdata.frame(m1_public, index = c("job_identifier", "resume_index")) 
fe_public_m1 <- plm(callback ~ conformity + non_conformity, data=dd_m1_public, model="within") 
model2<-coeftest(fe_public_m1, vcov=function(x) vcovHC(x, cluster="group", type="HC1"))
panel1<-stargazer(model1, model2,
                  title=c("Table A13 - Public panel (columns 1-2)"), 
                  digits=3, type="text", omit=c("Constant"),
                  omit.stat=c("all"), 
                  no.space = T, dep.var.labels.include = F,
                  add.lines = list(c("Apolitical callback", 
                                     rep(round(model1[1,1],digits=3),2)),
                                   c("Observation",rep(dim(m1_public)[1],2)))) 


## SOE sector
m1_soe<-subset(d_soe, merit == 1)
m0_soe<-subset(d_soe, merit == 0)
#Column 3: No control
ols.nc1.m1.soe <- lm(callback ~ conformity+non_conformity, data = m1_soe)
vcovCL.nc1.m1.soe<-cluster.vcov(ols.nc1.m1.soe, m1_soe$job_identifier)
model3<-coeftest(ols.nc1.m1.soe, vcov = vcovCL.nc1.m1.soe)
#Column 4: vacancy-fixed effects
dd_m1_soe <- pdata.frame(m1_soe, index = c("job_identifier", "resume_index")) 
fe_soe_m1 <- plm(callback ~ conformity + non_conformity, data=dd_m1_soe, model="within") 
model4<-coeftest(fe_soe_m1, vcov=function(x) vcovHC(x, cluster="group", type="HC1")) 
panel2<-stargazer(model3, model4,
                  title=c("SOE panel (columns 3-4)"), 
                  digits=3, type="text", omit=c("Constant"),
                  omit.stat=c("all"), 
                  no.space = T, dep.var.labels.include = F,
                  add.lines = list(c("Apolitical callback", 
                                     rep(round(model3[1,1],digits=3),2)),
                                   c("Observation",rep(dim(m1_soe)[1],2)))) 

## Private sector
m1_private<-subset(d_private, merit == 1)
m0_private<-subset(d_private, merit == 0)
#Column 5: No control
ols.nc1.m1.private <- lm(callback ~ conformity+non_conformity, data = m1_private) 
vcovCL.nc1.m1.private<-cluster.vcov(ols.nc1.m1.private, m1_private$job_identifier) 
model5<-coeftest(ols.nc1.m1.private, vcov = vcovCL.nc1.m1.private)
#Column 6: vacancy-fixed effects
dd_m1_private <- pdata.frame(m1_private, index = c("job_identifier", "resume_index")) 
fe_private_m1 <- plm(callback ~ conformity + non_conformity, data=dd_m1_private, model="within") 
model6<-coeftest(fe_private_m1, vcov=function(x) vcovHC(x, cluster="group", type="HC1"))
panel3<-stargazer(model5, model6,
                  title=c("Private panel (columns 5-6)"), 
                  digits=3, type="text", omit=c("Constant"),
                  omit.stat=c("all"), 
                  no.space = T, dep.var.labels.include = F,
                  add.lines = list(c("Apolitical callback", 
                                     rep(round(model5[1,1],digits=3),2)),
                                   c("Observation",rep(dim(m1_private)[1],2)))) 

## Foreign sector
m1_foreign<-subset(d_foreign, merit == 1)
m0_foreign<-subset(d_foreign, merit == 0)
#Column 7: No control
ols.nc1.m1.foreign <- lm(callback ~ conformity+non_conformity, data = m1_foreign) 
vcovCL.nc1.m1.foreign<-cluster.vcov(ols.nc1.m1.foreign, m1_foreign$job_identifier)
model7<-coeftest(ols.nc1.m1.foreign, vcov = vcovCL.nc1.m1.foreign)
#Column 8: vacancy-fixed effects
dd_m1_foreign <- pdata.frame(m1_foreign, index = c("job_identifier", "resume_index")) 
fe_foreign_m1 <- plm(callback ~ conformity + non_conformity, data=dd_m1_foreign, model="within")
model8<-coeftest(fe_foreign_m1, vcov=function(x) vcovHC(x, cluster="group", type="HC1"))
panel4<-stargazer(model7, model8,
                  title=c("Foreign panel (columns 7-8)"), 
                  digits=3, type="text", omit=c("Constant"),
                  omit.stat=c("all"), 
                  no.space = T, dep.var.labels.include = F,
                  add.lines = list(c("Apolitical callback", 
                                     rep(round(model7[1,1],digits=3),2)),
                                   c("Observation",rep(dim(m1_foreign)[1],2)))) 


## Save the table
results<-c(panel1,panel2,panel3,panel4)
write.table(results, file="Log/TableA13.txt", row.names = FALSE)


###############################
####### Table A14 #############
###############################
## Public sector
#Column 1: No control
ols.nc1.m0.public <- lm(callback ~ conformity+non_conformity, data = m0_public) 
vcovCL.nc1.m0.public<-cluster.vcov(ols.nc1.m0.public, m0_public$job_identifier)
model1<-coeftest(ols.nc1.m0.public, vcov = vcovCL.nc1.m0.public)
#Column 2: vacancy-fixed effects
dd_m0_public <- pdata.frame(m0_public, index = c("job_identifier", "resume_index")) 
fe_public_m0 <- plm(callback ~ conformity + non_conformity, data=dd_m0_public, model="within") 
model2<-coeftest(fe_public_m0, vcov=function(x) vcovHC(x, cluster="group", type="HC1"))
panel1<-stargazer(model1, model2,
                  title=c("Table A14 - Public panel (columns 1-2)"), 
                  digits=3, type="text", omit=c("Constant"),
                  omit.stat=c("all"), 
                  no.space = T, dep.var.labels.include = F,
                  add.lines = list(c("Apolitical callback", 
                                     rep(round(model1[1,1],digits=3),2)),
                                   c("Observation",rep(dim(m0_public)[1],2)))) 

## SOE sector
#Column 3: No control
ols.nc1.m0.soe <- lm(callback ~ conformity+non_conformity, data = m0_soe) 
vcovCL.nc1.m0.soe<-cluster.vcov(ols.nc1.m0.soe, m0_soe$job_identifier)
model3<-coeftest(ols.nc1.m0.soe, vcov = vcovCL.nc1.m0.soe)
#Column 4: vacancy-fixed effects
dd_m0_soe <- pdata.frame(m0_soe, index = c("job_identifier", "resume_index")) 
fe_soe_m0 <- plm(callback ~ conformity + non_conformity, data=dd_m0_soe, model="within")
model4<-coeftest(fe_soe_m0, vcov=function(x) vcovHC(x, cluster="group", type="HC1"))
panel2<-stargazer(model3, model4,
                  title=c("SOE panel (columns 3-4)"), 
                  digits=3, type="text", omit=c("Constant"),
                  omit.stat=c("all"), 
                  no.space = T, dep.var.labels.include = F,
                  add.lines = list(c("Apolitical callback", 
                                     rep(round(model3[1,1],digits=3),2)),
                                   c("Observation",rep(dim(m0_soe)[1],2)))) 

## Private sector
#Column 5: No control
ols.nc1.m0.private <- lm(callback ~ conformity+non_conformity, data = m0_private)
vcovCL.nc1.m0.private<-cluster.vcov(ols.nc1.m0.private, m0_private$job_identifier)
model5<-coeftest(ols.nc1.m0.private, vcov = vcovCL.nc1.m0.private)
#Column 6: vacancy-fixed effects
dd_m0_private <- pdata.frame(m0_private, index = c("job_identifier", "resume_index")) 
fe_private_m0 <- plm(callback ~ conformity + non_conformity, data=dd_m0_private, model="within") 
model6<-coeftest(fe_private_m0, vcov=function(x) vcovHC(x, cluster="group", type="HC1"))
panel3<-stargazer(model5, model6,
                  title=c("Private panel (columns 5-6)"), 
                  digits=3, type="text", omit=c("Constant"),
                  omit.stat=c("all"), 
                  no.space = T, dep.var.labels.include = F,
                  add.lines = list(c("Apolitical callback", 
                                     rep(round(model5[1,1],digits=3),2)),
                                   c("Observation",rep(dim(m0_private)[1],2)))) 

## Foreign sector
#Column 7: No control
ols.nc1.m0.foreign <- lm(callback ~ conformity+non_conformity, data = m0_foreign)
vcovCL.nc1.m0.foreign<-cluster.vcov(ols.nc1.m0.foreign, m0_foreign$job_identifier)
model7<-coeftest(ols.nc1.m0.foreign, vcov = vcovCL.nc1.m0.foreign)
#Column 8: vacancy-fixed effects
dd_m0_foreign <- pdata.frame(m0_foreign, index = c("job_identifier", "resume_index")) 
fe_foreign_m0 <- plm(callback ~ conformity + non_conformity, data=dd_m0_foreign, model="within")
model8<-coeftest(fe_foreign_m0, vcov=function(x) vcovHC(x, cluster="group", type="HC1"))
panel4<-stargazer(model7, model8,
                  title=c("Foreign panel (columns 7-8)"), 
                  digits=3, type="text", omit=c("Constant"),
                  omit.stat=c("all"), 
                  no.space = T, dep.var.labels.include = F,
                  add.lines = list(c("Apolitical callback", 
                                     rep(round(model7[1,1],digits=3),2)),
                                   c("Observation",rep(dim(m0_foreign)[1],2)))) 


## Save the table
results<-c(panel1,panel2,panel3,panel4)
write.table(results, file="Log/TableA14.txt", row.names = FALSE)


###############################
####### Table A15 #############
###############################
## Public sector
# Column 1: No control
ols.nc3.public <- lm(callback ~ merit + conformity + non_conformity, data = d_public)
vcovCL<-cluster.vcov(ols.nc3.public, d_public$job_identifier)
model1<-coeftest(ols.nc3.public, vcov = vcovCL) # regression estimates and s.e.
effect_merit <- coeftest(ols.nc3.public)[2,1] 
effect_loyalty <- coeftest(ols.nc3.public)[3,1]
effect_diff <- effect_loyalty - effect_merit 
var_effect_merit <- vcovCL[2,2]
var_effect_loyalty <- vcovCL[3,3]
cov_effect_merit_loyalty <- vcovCL[2,3]
effect_diff_tstat <- effect_diff / sqrt(var_effect_merit + var_effect_loyalty - 2*cov_effect_merit_loyalty)
effect_diff_pvalue1 <- 2*pt(effect_diff_tstat, df = nrow(d[d$public==1,])-4)   
# Column 2: Vacancy fixed-effects
dd_public <- pdata.frame(d_public, index = c("job_identifier", "resume_index")) 
ols.nc3.public.fe <- plm(callback ~ merit + conformity + non_conformity, data=dd_public, model="within")
model2<-coeftest(ols.nc3.public.fe, vcov=function(x) vcovHC(x, cluster="group", type="HC1"))
effect_merit <- coeftest(ols.nc3.public.fe)[1,1]
effect_loyalty <- coeftest(ols.nc3.public.fe)[2,1]
effect_diff <- effect_loyalty - effect_merit
var_effect_merit <- vcovCL[1,2]
var_effect_loyalty <- vcovCL[2,2]
cov_effect_merit_loyalty <- vcovCL[1,2]
effect_diff_tstat <- effect_diff / sqrt(var_effect_merit + var_effect_loyalty - 2*cov_effect_merit_loyalty)
effect_diff_pvalue2 <- 2*pt(effect_diff_tstat, df = nrow(d[d$public==1,])-4)   

panel1<-stargazer(model1, model2,
                  title=c("Table A15-Public panel (columns 1-2)"), 
                  digits=3, type="text", omit=c("Constant"),
                  omit.stat=c("all"), order=c(2,3,1),
                  covariate.labels = c("Conformity","Non-conformity","High merit (top 5% cohort)"),
                  no.space = T, dep.var.labels.include = F,
                  add.lines = list(c("Apolitical average merit callback", 
                                     rep(round(model1[1,1],digits=3),2)),
                                   c("p-value for diff in effects", round(effect_diff_pvalue1, digits=3), round(effect_diff_pvalue2,digits=3)),
                                   c("Observation",rep(dim(d_public)[1],2)))) 


## SOE sector
# Column 3: No control
ols.nc3.soe <- lm(callback ~ merit + conformity + non_conformity, data = d_soe) 
vcovCL<-cluster.vcov(ols.nc3.soe, d_soe$job_identifier)
model3<-coeftest(ols.nc3.soe, vcov = vcovCL) # regression estimates and s.e.
effect_merit <- coeftest(ols.nc3.soe)[2,1]
effect_loyalty <- coeftest(ols.nc3.soe)[3,1]
effect_diff <- effect_loyalty - effect_merit
var_effect_merit <- vcovCL[2,2]
var_effect_loyalty <- vcovCL[3,3]
cov_effect_merit_loyalty <- vcovCL[2,3]
effect_diff_tstat <- effect_diff / sqrt(var_effect_merit + var_effect_loyalty - 2*cov_effect_merit_loyalty)
effect_diff_pvalue3 <- 2*pt(effect_diff_tstat, lower.tail=FALSE,df = nrow(d[d$soe==1,])-4)   
#Column 4: Vacancy fixed-effects
dd_soe <- pdata.frame(d_soe, index = c("job_identifier", "resume_index")) 
ols.nc3.soe.fe <- plm(callback ~ merit + conformity + non_conformity, data=dd_soe, model="within") 
model4<-coeftest(ols.nc3.soe.fe, vcov=function(x) vcovHC(x, cluster="group", type="HC1")) # regression estimates and s.e.
effect_merit <- coeftest(ols.nc3.soe.fe)[1,1]
effect_loyalty <- coeftest(ols.nc3.soe.fe)[2,1]
effect_diff <- effect_loyalty - effect_merit
var_effect_merit <- vcovCL[1,2]
var_effect_loyalty <- vcovCL[2,2]
cov_effect_merit_loyalty <- vcovCL[1,2]
effect_diff_tstat <- effect_diff / sqrt(var_effect_merit + var_effect_loyalty - 2*cov_effect_merit_loyalty)
effect_diff_pvalue4 <- 2*pt(effect_diff_tstat, lower.tail=FALSE,df = nrow(d[d$soe==1,])-4)   

panel2<-stargazer(model3, model4,
                  title=c("SOE panel (columns 3-4)"), 
                  digits=3, type="text", omit=c("Constant"),
                  omit.stat=c("all"), order=c(2,3,1),
                  covariate.labels = c("Conformity","Non-conformity","High merit (top 5% cohort)"),
                  no.space = T, dep.var.labels.include = F,
                  add.lines = list(c("Apolitical average merit callback", 
                                     rep(round(model3[1,1],digits=3),2)),
                                   c("p-value for diff in effects", round(effect_diff_pvalue3, digits=3), round(effect_diff_pvalue4,digits=3)),
                                   c("Observation",rep(dim(d_soe)[1],2)))) 


## Private
# Column 5: No control
ols.nc3.private <- lm(callback ~ merit + conformity + non_conformity, data = d_private) 
vcovCL<-cluster.vcov(ols.nc3.private, d_private$job_identifier)
model5<-coeftest(ols.nc3.private, vcov = vcovCL) # regression estimates and s.e.
effect_merit <- coeftest(ols.nc3.private)[2,1]
effect_loyalty <- coeftest(ols.nc3.private)[3,1]
effect_diff <- effect_loyalty - effect_merit
var_effect_merit <- vcovCL[2,2]
var_effect_loyalty <- vcovCL[3,3]
cov_effect_merit_loyalty <- vcovCL[2,3]
effect_diff_tstat <- effect_diff / sqrt(var_effect_merit + var_effect_loyalty - 2*cov_effect_merit_loyalty)
effect_diff_pvalue5 <- 2*pt(effect_diff_tstat, df = nrow(d[d$private==1,])-4)   
# Column 6: Vacancy fixed-effects
dd_private <- pdata.frame(d_private, index = c("job_identifier", "resume_index")) 
ols.nc3.private.fe <- plm(callback ~ merit + conformity + non_conformity, data=dd_private, model="within")
model6<-coeftest(ols.nc3.private.fe, vcov=function(x) vcovHC(x, cluster="group", type="HC1"))
effect_merit <- coeftest(ols.nc3.private.fe)[1,1]
effect_loyalty <- coeftest(ols.nc3.private.fe)[2,1]
effect_diff <- effect_loyalty - effect_merit
var_effect_merit <- vcovCL[1,2]
var_effect_loyalty <- vcovCL[2,2]
cov_effect_merit_loyalty <- vcovCL[1,2]
effect_diff_tstat <- effect_diff / sqrt(var_effect_merit + var_effect_loyalty - 2*cov_effect_merit_loyalty)
effect_diff_pvalue6 <- 2*pt(effect_diff_tstat, df = nrow(d[d$private==1,])-4)   

panel3<-stargazer(model5, model6,
                  title=c("Private panel (columns 5-6)"), 
                  digits=3, type="text", omit=c("Constant"),
                  omit.stat=c("all"), order=c(2,3,1),
                  covariate.labels = c("Conformity","Non-conformity","High merit (top 5% cohort)"),
                  no.space = T, dep.var.labels.include = F,
                  add.lines = list(c("Apolitical average merit callback", 
                                     rep(round(model5[1,1],digits=3),2)),
                                   c("p-value for diff in effects", round(effect_diff_pvalue5, digits=3), round(effect_diff_pvalue6,digits=3)),
                                   c("Observation",rep(dim(d_private)[1],2)))) 

## Foreign
# Column 7: No control
ols.nc3.foreign <- lm(callback ~ merit + conformity + non_conformity, data = d_foreign) 
vcovCL<-cluster.vcov(ols.nc3.foreign, d_foreign$job_identifier)
model7<-coeftest(ols.nc3.foreign, vcov = vcovCL) #regression estimates and s.e.
effect_merit <- coeftest(ols.nc3.foreign)[2,1]
effect_loyalty <- coeftest(ols.nc3.foreign)[3,1]
effect_diff <- effect_loyalty - effect_merit
var_effect_merit <- vcovCL[2,2]
var_effect_loyalty <- vcovCL[3,3]
cov_effect_merit_loyalty <- vcovCL[2,3]
effect_diff_tstat <- effect_diff / sqrt(var_effect_merit + var_effect_loyalty - 2*cov_effect_merit_loyalty)
effect_diff_pvalue7 <- 2*pt(effect_diff_tstat, lower.tail=FALSE, df = nrow(d[d$foreign==1,])-4)   
#Column 8: Vacancy fixed-effects
dd_foreign <- pdata.frame(d_foreign, index = c("job_identifier", "resume_index")) 
ols.nc3.foreign.fe <- plm(callback ~ merit + conformity + non_conformity, data=dd_foreign, model="within")
model8<-coeftest(ols.nc3.foreign.fe, vcov=function(x) vcovHC(x, cluster="group", type="HC1"))
effect_merit <- coeftest(ols.nc3.foreign.fe)[1,1]
effect_loyalty <- coeftest(ols.nc3.foreign.fe)[2,1]
effect_diff <- effect_loyalty - effect_merit
var_effect_merit <- vcovCL[1,2]
var_effect_loyalty <- vcovCL[2,2]
cov_effect_merit_loyalty <- vcovCL[1,2]
effect_diff_tstat <- effect_diff / sqrt(var_effect_merit + var_effect_loyalty - 2*cov_effect_merit_loyalty)
effect_diff_pvalue8 <- 2*pt(effect_diff_tstat, lower.tail=FALSE, df = nrow(d[d$foreign==1,])-4)   

panel4<-stargazer(model7, model8,
                  title=c("Foreign panel (columns 7-8)"), 
                  digits=3, type="text", omit=c("Constant"),
                  omit.stat=c("all"), order=c(2,3,1),
                  covariate.labels = c("Conformity","Non-conformity","High merit (top 5% cohort)"),
                  no.space = T, dep.var.labels.include = F,
                  add.lines = list(c("Apolitical average merit callback", 
                                     rep(round(model7[1,1],digits=3),2)),
                                   c("p-value for diff in effects", round(effect_diff_pvalue7, digits=3), round(effect_diff_pvalue8,digits=3)),
                                   c("Observation",rep(dim(d_foreign)[1],2)))) 


## Save the table
results<-c(panel1,panel2,panel3,panel4)
write.table(results, file="Log/TableA15.txt", row.names = FALSE)



###############################
####### Table A16 #############
###############################
## Public sector
# Column 1: No control
ols.nc3.public <- lm(callback ~ male + conformity + non_conformity, data = d_public) 
vcovCL<-cluster.vcov(ols.nc3.public, d_public$job_identifier)
model1<-coeftest(ols.nc3.public, vcov = vcovCL) #regression estimates and s.e.
effect_male <- coeftest(ols.nc3.public)[2,1]
effect_loyalty <- coeftest(ols.nc3.public)[3,1]
effect_diff <- effect_loyalty - effect_male
var_effect_male <- vcovCL[2,2]
var_effect_loyalty <- vcovCL[3,3]
cov_effect_male_loyalty <- vcovCL[2,3]
effect_diff_tstat <- effect_diff / sqrt(var_effect_male + var_effect_loyalty - 2*cov_effect_male_loyalty)
effect_diff_pvalue1 <- 2*pt(effect_diff_tstat, df = nrow(d[d$public==1,])-4)   
#Column 2: Vacancy fixed-effects
dd_public <- pdata.frame(d_public, index = c("job_identifier", "resume_index")) 
ols.nc3.public.fe <- plm(callback ~ male + conformity + non_conformity, data=dd_public, model="within") 
model2<-coeftest(ols.nc3.public.fe, vcov=function(x) vcovHC(x, cluster="group", type="HC1"))
effect_male <- coeftest(ols.nc3.public.fe)[1,1]
effect_loyalty <- coeftest(ols.nc3.public.fe)[2,1]
effect_diff <- effect_loyalty - effect_male
var_effect_male <- vcovCL[1,2]
var_effect_loyalty <- vcovCL[2,2]
cov_effect_male_loyalty <- vcovCL[1,2]
effect_diff_tstat <- effect_diff / sqrt(var_effect_male + var_effect_loyalty - 2*cov_effect_male_loyalty)
effect_diff_pvalue2 <- 2*pt(effect_diff_tstat, df = nrow(d[d$public==1,])-4)   

panel1<-stargazer(model1, model2,
                  title=c("Table A16-Public panel (columns 1-2)"), 
                  digits=3, type="text", omit=c("Constant"),
                  omit.stat=c("all"), order=c(2,3,1),
                  covariate.labels = c("Conformity","Non-conformity","Male"),
                  no.space = T, dep.var.labels.include = F,
                  add.lines = list(c("Apolitical average merit callback", 
                                     rep(round(model1[1,1],digits=3),2)),
                                   c("p-value for diff in effects", round(effect_diff_pvalue1, digits=3), round(effect_diff_pvalue2,digits=3)),
                                   c("Observation",rep(dim(d_public)[1],2)))) 

## SOE sector
# Column 3: No control
ols.nc3.soe <- lm(callback ~ male + conformity + non_conformity, data = d_soe) 
vcovCL<-cluster.vcov(ols.nc3.soe, d_soe$job_identifier) 
model3<-coeftest(ols.nc3.soe, vcov = vcovCL) #regression estimates and s.e.
effect_male <- coeftest(ols.nc3.soe)[2,1]
effect_loyalty <- coeftest(ols.nc3.soe)[3,1]
effect_diff <- effect_loyalty - effect_male
var_effect_male <- vcovCL[2,2]
var_effect_loyalty <- vcovCL[3,3]
cov_effect_male_loyalty <- vcovCL[2,3]
effect_diff_tstat <- effect_diff / sqrt(var_effect_male + var_effect_loyalty - 2*cov_effect_male_loyalty)
effect_diff_pvalue3 <- 2*pt(effect_diff_tstat, df = nrow(d[d$soe==1,])-4)   
# Column 4: Vacancy fixed-effects
dd_soe <- pdata.frame(d_soe, index = c("job_identifier", "resume_index")) 
ols.nc3.soe.fe <- plm(callback ~ male + conformity + non_conformity, data=dd_soe, model="within")
model4<-coeftest(ols.nc3.soe.fe, vcov=function(x) vcovHC(x, cluster="group", type="HC1"))
effect_male <- coeftest(ols.nc3.soe.fe)[1,1]
effect_loyalty <- coeftest(ols.nc3.soe.fe)[2,1]
effect_diff <- effect_loyalty - effect_male
var_effect_male <- vcovCL[1,2]
var_effect_loyalty <- vcovCL[2,2]
cov_effect_male_loyalty <- vcovCL[1,2]
effect_diff_tstat <- effect_diff / sqrt(var_effect_male + var_effect_loyalty - 2*cov_effect_male_loyalty)
effect_diff_pvalue4 <- 2*pt(effect_diff_tstat, df = nrow(d[d$soe==1,])-4)   

panel2<-stargazer(model3, model4,
                  title=c("SOE panel (columns 3-4)"), 
                  digits=3, type="text", omit=c("Constant"),
                  omit.stat=c("all"), order=c(2,3,1),
                  covariate.labels = c("Conformity","Non-conformity","Male"),
                  no.space = T, dep.var.labels.include = F,
                  add.lines = list(c("Apolitical average merit callback", 
                                     rep(round(model3[1,1],digits=3),2)),
                                   c("p-value for diff in effects", round(effect_diff_pvalue3, digits=3), round(effect_diff_pvalue4,digits=3)),
                                   c("Observation",rep(dim(d_soe)[1],2)))) 

## Private sector
# Column 5: No control
ols.nc3.private <- lm(callback ~ male + conformity + non_conformity, data = d_private) 
vcovCL<-cluster.vcov(ols.nc3.private, d_private$job_identifier)
model5<-coeftest(ols.nc3.private, vcov = vcovCL) #regression estimates and s.e.
effect_male <- coeftest(ols.nc3.private)[2,1]
effect_loyalty <- coeftest(ols.nc3.private)[3,1]
effect_diff <- effect_loyalty - effect_male
var_effect_male <- vcovCL[2,2]
var_effect_loyalty <- vcovCL[3,3]
cov_effect_male_loyalty <- vcovCL[2,3]
effect_diff_tstat <- effect_diff / sqrt(var_effect_male + var_effect_loyalty - 2*cov_effect_male_loyalty)
effect_diff_pvalue5 <- 2*pt(effect_diff_tstat, df = nrow(d[d$private==1,])-4)   
# Column 6: Vacancy fixed-effects
dd_private <- pdata.frame(d_private, index = c("job_identifier", "resume_index")) 
ols.nc3.private.fe <- plm(callback ~ male + conformity + non_conformity, data=dd_private, model="within") 
model6<-coeftest(ols.nc3.private.fe, vcov=function(x) vcovHC(x, cluster="group", type="HC1"))
effect_male <- coeftest(ols.nc3.private.fe)[1,1]
effect_loyalty <- coeftest(ols.nc3.private.fe)[2,1]
effect_diff <- effect_loyalty - effect_male
var_effect_male <- vcovCL[1,2]
var_effect_loyalty <- vcovCL[2,2]
cov_effect_male_loyalty <- vcovCL[1,2]
effect_diff_tstat <- effect_diff / sqrt(var_effect_male + var_effect_loyalty - 2*cov_effect_male_loyalty)
effect_diff_pvalue6 <- 2*pt(effect_diff_tstat, df = nrow(d[d$private==1,])-4)   

panel3<-stargazer(model5, model6,
                  title=c("Private panel (columns 5-6)"), 
                  digits=3, type="text", omit=c("Constant"),
                  omit.stat=c("all"), order=c(2,3,1),
                  covariate.labels = c("Conformity","Non-conformity","Male"),
                  no.space = T, dep.var.labels.include = F,
                  add.lines = list(c("Apolitical average merit callback", 
                                     rep(round(model5[1,1],digits=3),2)),
                                   c("p-value for diff in effects", round(effect_diff_pvalue5, digits=3), round(effect_diff_pvalue6,digits=3)),
                                   c("Observation",rep(dim(d_private)[1],2)))) 


## Foreign sector
# Column 7: No control
ols.nc3.foreign <- lm(callback ~ male + conformity + non_conformity, data = d_foreign) 
vcovCL<-cluster.vcov(ols.nc3.foreign, d_foreign$job_identifier)
model7<-coeftest(ols.nc3.foreign, vcov = vcovCL) #regression estimates and s.e.
effect_male <- coeftest(ols.nc3.foreign)[2,1]
effect_loyalty <- coeftest(ols.nc3.foreign)[3,1]
effect_diff <- effect_loyalty - effect_male
var_effect_male <- vcovCL[2,2]
var_effect_loyalty <- vcovCL[3,3]
cov_effect_male_loyalty <- vcovCL[2,3]
effect_diff_tstat <- effect_diff / sqrt(var_effect_male + var_effect_loyalty - 2*cov_effect_male_loyalty)
effect_diff_pvalue7 <- 2*pt(effect_diff_tstat, df = nrow(d[d$foreign==1,])-4)   
#Column 8: Vacancy fixed-effects
dd_foreign <- pdata.frame(d_foreign, index = c("job_identifier", "resume_index")) 
ols.nc3.foreign.fe <- plm(callback ~ male + conformity + non_conformity, data=dd_foreign, model="within")
model8<-coeftest(ols.nc3.foreign.fe, vcov=function(x) vcovHC(x, cluster="group", type="HC1"))
effect_male <- coeftest(ols.nc3.foreign.fe)[1,1]
effect_loyalty <- coeftest(ols.nc3.foreign.fe)[2,1]
effect_diff <- effect_loyalty - effect_male
var_effect_male <- vcovCL[1,2]
var_effect_loyalty <- vcovCL[2,2]
cov_effect_male_loyalty <- vcovCL[1,2]
effect_diff_tstat <- effect_diff / sqrt(var_effect_male + var_effect_loyalty - 2*cov_effect_male_loyalty)
effect_diff_pvalue8 <- 2*pt(effect_diff_tstat, df = nrow(d[d$foreign==1,])-4)   

panel4<-stargazer(model7, model8,
                  title=c("Foreign panel (columns 7-8)"), 
                  digits=3, type="text", omit=c("Constant"),
                  omit.stat=c("all"), order=c(2,3,1),
                  covariate.labels = c("Conformity","Non-conformity","Male"),
                  no.space = T, dep.var.labels.include = F,
                  add.lines = list(c("Apolitical average merit callback", 
                                     rep(round(model7[1,1],digits=3),2)),
                                   c("p-value for diff in effects", round(effect_diff_pvalue7, digits=3), round(effect_diff_pvalue8,digits=3)),
                                   c("Observation",rep(dim(d_foreign)[1],2)))) 


## Save the table
results<-c(panel1,panel2,panel3,panel4)
write.table(results, file="Log/TableA16.txt", row.names = FALSE)


######################################################################################
## Section A.5 Hiring Manager Conjoint Survey Experiment Details
######################################################################################
rm(list=ls())
data<-read.csv("Data/HRSurvey.csv", sep=",", header=TRUE, stringsAsFactors = FALSE)
colnames(data)

###############################
####### Table A17 #############
###############################
results<-matrix(NA,ncol=2,nrow=32)
colnames(results)<-c("Characteristics","Sample mean")
results[,1]<-c("Female","Age (years)","Ethnic minorities (non-Han)", "Urban residents",
               "CCP member","Have direct reports","By work experience","1-3 years",
               "4-7 years","8 years or above","By HR experience","1-3 years", "4-7 years",
               "8 years or above", "By Hukou region", "Eastern China","Middle China",
               "Western China", "By educational level","High school and below",
               "Bachelor", "Graduate", "By ownership sector", "Public institution",
               "State-owned enterprise", "Private firm", "Foreign/Joint venture",
               "By monthly income (RMB)", "Low (<=5,000)", "Middle (5001-8000)", 
               "Upper middle (8001-20000)", "High (>=20001)")
results<-as.data.frame(results)
# Female
results$`Sample mean`[1]<-round(mean(data$female), digits=3)
# Age
results$`Sample mean`[2]<-round(mean(data$age), digits=1)
# Ethnic minorities (non-Han)
results$`Sample mean`[3]<-round(mean(data$nonHan), digits=3)
# Urban residents
results$`Sample mean`[4]<-round(mean(data$urban), digits=3)
# CCP membership
results$`Sample mean`[5]<-round(mean(data$ccp), digits=3)
# Have direct reports
results$`Sample mean`[6]<-round(mean(data$manager), digits=3)
# By years of work experience
results$`Sample mean`[8]<-round(mean(data$exp_1_3), digits=3) #1-3 years
results$`Sample mean`[9]<-round(mean(data$exp_4_7), digits=3) #4-7 years
results$`Sample mean`[10]<-round(mean(data$exp_8more), digits=3) #8+ years
# By years of HR experience
results$`Sample mean`[12]<-round(mean(data$hrexp_1_3), digits=3) #1-3 years
results$`Sample mean`[13]<-round(mean(data$hrexp_4_7), digits=3) #4-7 years
results$`Sample mean`[14]<-round(mean(data$hrexp_8more), digits=3) #8+ years
# By Hukou region
results$`Sample mean`[16]<-round(mean(data$HukouEast), digits=3)
results$`Sample mean`[17]<-round(mean(data$HukouMiddle), digits=3)
results$`Sample mean`[18]<-round(mean(data$HukouWest), digits=3)
# By education level
results$`Sample mean`[20]<-round(mean(data$hs), digits=3) #high school or below
results$`Sample mean`[21]<-round(mean(data$bachelor), digits=3) #bachelor
results$`Sample mean`[22]<-round(mean(data$graduate), digits=3) #graduate
# By ownership sector
results$`Sample mean`[24]<-round(mean(data$gov),digits=4)
results$`Sample mean`[25]<-round(mean(data$soe),digits=3)
results$`Sample mean`[26]<-round(mean(data$private),digits=3)
results$`Sample mean`[27]<-round(mean(data$foreign),digits=3)
# By monthly income
results$`Sample mean`[29]<-round(mean(data$inc_low,na.rm=T),digits=3) #low
results$`Sample mean`[30]<-round(mean(data$inc_mid,na.rm=T),digits=3) #middle
results$`Sample mean`[31]<-round(mean(data$inc_upmid,na.rm=T),digits=3) #upper middle
results$`Sample mean`[32]<-round(mean(data$inc_high,na.rm=T),digits=3) #high

# Save the table
results<-stargazer(results,title="Table A17",
                   type="text",summary=FALSE)
write.table(results, file="Log/TableA17.txt", row.names = FALSE)


###############################
####### Table A18 #############
###############################
obs<-rep(1518,6)
apolitical<-rep(NA,6)
conformity<-rep(NA,6)
nonconformity<-rep(NA,6)
pvalues<-rep(NA,6)
# High merit
apolitical[1]<-mean(data$resume_highmerit[data$resume_allegiance=="comic"])
conformity[1]<-mean(data$resume_highmerit[data$resume_allegiance=="Socialism"])
nonconformity[1]<-mean(data$resume_highmerit[data$resume_allegiance=="West"])
merit<-summary(lm(resume_highmerit~conformity+non_conformity,data=data))
pvalues[1]<-pf(merit$fstatistic[1],merit$fstatistic[2],merit$fstatistic[3], lower.tail=FALSE)
# Gender
apolitical[2]<-mean(data$resume_male[data$resume_allegiance=="comic"])
conformity[2]<-mean(data$resume_male[data$resume_allegiance=="Socialism"])
nonconformity[2]<-mean(data$resume_male[data$resume_allegiance=="West"])
gender<-summary(lm(resume_male~conformity+non_conformity,data=data))
pvalues[2]<-pf(gender$fstatistic[1],gender$fstatistic[2],gender$fstatistic[3], lower.tail=FALSE)
# CCP
apolitical[3]<-mean(data$resume_ccp[data$resume_allegiance=="comic"])
conformity[3]<-mean(data$resume_ccp[data$resume_allegiance=="Socialism"])
nonconformity[3]<-mean(data$resume_ccp[data$resume_allegiance=="West"])
ccp<-summary(lm(resume_ccp~conformity+non_conformity,data=data))
pvalues[3]<-pf(ccp$fstatistic[1],ccp$fstatistic[2],ccp$fstatistic[3], lower.tail=FALSE)
# University prestige
apolitical[4]<-mean(data$resume_hightierU[data$resume_allegiance=="comic"])
conformity[4]<-mean(data$resume_hightierU[data$resume_allegiance=="Socialism"])
nonconformity[4]<-mean(data$resume_hightierU[data$resume_allegiance=="West"])
Uprestige<-summary(lm(resume_hightierU~conformity+non_conformity,data=data))
pvalues[4]<-pf(Uprestige$fstatistic[1],Uprestige$fstatistic[2],Uprestige$fstatistic[3], lower.tail=FALSE)
# Explicit political statement bullet
apolitical[5]<-mean(data$resume_statement[data$resume_allegiance=="comic"])
conformity[5]<-mean(data$resume_statement[data$resume_allegiance=="Socialism"])
nonconformity[5]<-mean(data$resume_statement[data$resume_allegiance=="West"])
politicalbullet<-summary(lm(resume_statement~conformity+non_conformity,data=data))
pvalues[5]<-pf(politicalbullet$fstatistic[1],politicalbullet$fstatistic[2],
               politicalbullet$fstatistic[3], lower.tail=FALSE)
# Science & Engineering major
apolitical[6]<-mean(data$resume_STEMMajor[data$resume_allegiance=="comic"])
conformity[6]<-mean(data$resume_STEMMajor[data$resume_allegiance=="Socialism"])
nonconformity[6]<-mean(data$resume_STEMMajor[data$resume_allegiance=="West"])
stem<-summary(lm(resume_STEMMajor~conformity+non_conformity,data=data))
pvalues[6]<-pf(stem$fstatistic[1],stem$fstatistic[2],stem$fstatistic[3], lower.tail=FALSE)

# Table A18
BalanceT<-cbind.data.frame(obs,apolitical,conformity,nonconformity,pvalues)
row.names(BalanceT)<-c("High merit","Male","CCP member","High-tier university",
                       "Explicit political statement","Science/Engineering major")
results<-round(BalanceT,digits=3)
colnames(results)<-c("Obs","Apolitical","Conformity","Non-conformity","p-value")

# Save the table
results<-stargazer(results,title="Table A18",
                   type="text",summary=FALSE)
write.table(results, file="Log/TableA18.txt", row.names = FALSE)



###############################
####### Table A19 #############
###############################
ReportedCallbacks<-rep(NA,8) #reported callbacks by respondents
Obs<-rep(NA,8) #number of resumes
# Overall
ReportedCallbacks[1]<-prop.table(table(data$Y))[2]
Obs[1]<-dim(data)[1]
# By treatment
ReportedCallbacks[2]<-prop.table(table(data$Y[data$apolitical==1]))[2]
ReportedCallbacks[3]<-prop.table(table(data$Y[data$conformity==1]))[2]
ReportedCallbacks[4]<-prop.table(table(data$Y[data$non_conformity==1]))[2]
Obs[2]<-sum(data$apolitical==1)
Obs[3]<-sum(data$conformity==1)
Obs[4]<-sum(data$non_conformity==1)
# By ownership sector
d_gov<-data[data$gov==1,]
d_soe<-data[data$soe==1,]
d_private<-data[data$private==1,]
d_foreign<-data[data$foreign==1,]
ReportedCallbacks[5]<-prop.table(table(d_gov$Y))[2]
ReportedCallbacks[6]<-prop.table(table(d_soe$Y))[2]
ReportedCallbacks[7]<-prop.table(table(d_private$Y))[2]
ReportedCallbacks[8]<-prop.table(table(d_foreign$Y))[2]
Obs[5]<-sum(data$gov==1)
Obs[6]<-sum(data$soe==1)
Obs[7]<-sum(data$private==1)
Obs[8]<-sum(data$foreign==1)

# Table A19
SummaryStats<-cbind.data.frame(ReportedCallbacks,Obs)
row.names(SummaryStats)<-c("Overall","Apolitical","Conformity","Non-conformity",
                           "Public institution","State-owned enterprise",
                           "Private firm","Foreign/Joint venture")
results<-round(SummaryStats,digits=3)
colnames(results)<-c("Reported callback rate", "No.of resume")

# Save the table
results<-stargazer(results,title="Table A19",
                   type="text",summary=FALSE)
write.table(results, file="Log/TableA19.txt", row.names = FALSE)

